package com.filetest;

import org.junit.Test;

import java.io.*;

public class InOut {

    @Test
    public void test1() throws IOException {
        File f = new File("E:" + File.separator + "demo.txt");
        OutputStream os = new FileOutputStream(f, true);
        String str = "白家奇哈哈哈";
        os.write(str.getBytes());
        os.close();

        FileInputStream in = new FileInputStream(f);
        byte[] buf = new byte[1024];
        int len = in.read(buf);
        System.out.println(new String(buf, 0, len));
    }


    @Test
    public void test2() throws Exception {
        byte[] data = new byte[100];

        FileInputStream in = new FileInputStream("E:/" + "demo.txt");
        FileOutputStream os = new FileOutputStream("E:/" + "democopy.txt");

        BufferedInputStream bufin = new BufferedInputStream(in);
        BufferedOutputStream bufos = new BufferedOutputStream(os);
        int count = 0;

        while ((count=bufin.read(data))!=-1) {
            bufos.write(data,0,count);
        }

        bufos.flush();
        bufin.close();
        bufos.close();
    }
}
